﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QWeiBoN.UserControler
{
    public partial class FaceList : UserControl
    {

        /// <summary>
        /// 选中表情
        /// </summary>
        public Action<string> Selected { get; set; }

        public FaceList()
        {
            InitializeComponent();
            FaceListBox.ItemsSource = Util.FaceHelper.Faces();
        }

        /// <summary>
        /// 屏幕尺寸
        /// </summary>
        private Size renderSize
        {
            get
            {
                return App.Current.RootVisual.RenderSize;
            }
        }

        /// <summary>
        /// 切换显示
        /// </summary>
        public void ToggleShow()
        {
            Dispatcher.BeginInvoke(() =>
            {
                FaceListGrid.Width = renderSize.Width;
                FaceListGrid.Height = renderSize.Height;
                popFaceList.IsOpen = !popFaceList.IsOpen;
            });
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="callback"></param>
        public void Show(Action callback = null)
        {
            Dispatcher.BeginInvoke(() =>
            {
                FaceListGrid.Width = renderSize.Width;
                FaceListGrid.Height = renderSize.Height;
                popFaceList.IsOpen = true;
                if (callback != null)
                {
                    callback();
                }
            });
        }

        /// <summary>
        /// 隐藏
        /// </summary>
        public void Hide()
        {
            Dispatcher.BeginInvoke(() =>
            {
                popFaceList.IsOpen = false;
            });
        }

        private void FaceImage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var face = (System.Windows.Controls.Image)sender;
            var code = "/" + face.Tag.ToString();
            popFaceList.IsOpen = false;
            if (Selected != null)
            {
                Selected(code);
            }
        }
    }
}
